/**
 * Copyright By Nanjing Fujitsu Nanda Software Technology Co., Ltd
 * 上午10:12:32
 * CoreCompanyDao.java
 * 
 */
package com.fujitsu.nanjing.mobile.dao;

import com.fujitsu.nanjing.mobile.exception.NotOneException;
import com.fujitsu.nanjing.mobile.model.hibernate.CoreCompany;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author qixb.fnst
 * 
 */
@Repository
public class CoreCompanyDao extends BaseDao<CoreCompany> {

    /**
     * qixib.fnst
     * 
     * @param whereClause
     * @return
     */
    public int getCompanyNums(String whereClause) {
        return queryNums(CoreCompany.class, whereClause);
    }

    public List<CoreCompany> getCompanies(String orderClause,
            String whereClause, boolean userLimit, int firstRecord, int limit) {
        return query4Page(CoreCompany.class, orderClause, whereClause,
                userLimit, firstRecord, limit);

    }

    /**
     * qixib.fnst
     * 
     * @param companyId
     * @return
     * @throws NotOneException
     */
    public CoreCompany getCompanyByCompanyId(int companyId)
            throws NotOneException {
        Session session = getSession();
        Criteria criteria = session.createCriteria(CoreCompany.class).add(
                Restrictions.eq("id", companyId));
        return query4One(criteria);
    }

}
